package com.xiaoxi.facademode.writer;

import java.io.IOException;
import java.io.Writer;

/**
 * @Author xiaoxi
 * @ProjectName design_mode
 * @PackageName com.xiaoxi.facademode.writer
 * @ClassName HtmlWriter
 * @Description TODO
 * @Date 2023/3/23 20:54
 * @Version 1.0
 */
public class HtmlWriter {

    private Writer writer;

    public HtmlWriter(Writer writer) {
        this.writer = writer;
    }

    public void title(String title) throws IOException {
        writer.write("<html>");
        writer.write("<head>");
        writer.write("<title>" + title + "</title>");
        writer.write("</head>");
        writer.write("<body>");
        writer.write("<h1>" + title + "</h1>\n");
        writer.flush();
    }

    public void text(String msg) throws IOException {
        writer.write("<p>" + msg + "</p>\n");
        writer.flush();
    }

    public void link(String href, String caption) throws IOException {
        writer.write("<a href=\"" + href + "\">" + caption + "</a>\n");
        writer.flush();
    }

    public void close() throws IOException {
        writer.write("</body>");
        writer.write("</html>");
        writer.close();
    }

}
